package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.utils.SendUtil;
import com.bcu.calculus.entity.Slist;
import com.bcu.calculus.entity.Message;
import com.bcu.calculus.mapper.SlistMapper;
import com.bcu.calculus.service.SlistService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class SlistServiceImpl implements SlistService {
    private Logger logger= LoggerFactory.getLogger(getClass());

    @Resource
    private SlistMapper slistMapper;

    @Override
    public Message<?> addSlist(Slist slist) {
        slist.setSlistPostTime(new Date());
        String slistId = "SL" + SendUtil.genSendId();
        slist.setSlistId(slistId);
        logger.info("二级标题-----增加,slistId为 "+slist.getSlistId());
        return slistMapper.insertSelective(slist) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> delSlist(String slistId) {
        logger.info("二级标题-----删除,slistId为 "+slistId);
        return slistMapper.deleteByPrimaryKey(slistId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateSlist(Slist slist) {
        logger.info("二级标题-----修改,slistId为 "+slist.getSlistId());
        return slistMapper.updateByPrimaryKeySelective(slist) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Slist> selectOneSlistById(String slistId) {
        logger.info("二级标题-----通过主键获得标题,slistId为 "+slistId);
        return Message.success(null).add(slistMapper.selectByPrimaryKey(slistId));
    }

    @Override
    public Message<List<Slist>> selectAllSlist() {
        logger.info("二级标题-----查询全部二级标题");
        return Message.success(null).add(slistMapper.selectAll());
    }

    @Override
    public Message<List<Slist>> getSlistByFlistId(String flistId) {
        logger.info("二级标题-----通过一级标题编号得到二级标题,flistId为 "+flistId);
        return Message.success(null).add(slistMapper.getSlistByFlistId(flistId));
    }

    @Override
    public Message<List<Slist>> getSlistByuserType(String userType) {
        logger.info("二级标题-----通过用户类型获得二级标题,userType为 "+userType);
        return Message.success(null).add(slistMapper.getSlistByUserType(userType));
    }

    @Override
    public Message<Slist> getSlistByTlistId(String tlistId) {
        logger.info("二级标题-----通过三tlisId获取所属的二级标题,titlisId为 "+tlistId);
        return Message.success(null).add(slistMapper.getSlistByTlistId(tlistId));
    }

}
